package cn.jlonely.xyhx.admin.service.impl;

import cn.jlonely.xyhx.admin.mapper.RankingMapper;
import cn.jlonely.xyhx.pojo.Ranking;
import cn.jlonely.xyhx.admin.service.RankingService;
import cn.jlonely.xyhx.pojo.vo.CommentPageVo;
import cn.jlonely.xyhx.utils.PageResult;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service("adminRankingService")
public class RankingServiceImpl implements RankingService {

    @Autowired
    private RankingMapper rankingMapper;


    /**
     * 获取所有榜单信息
     * @param topic
     * @param id
     * @return
     */
    @Override
    public List<Ranking> getRankingInfoAll(String topic, Integer id) {

        return rankingMapper.getRankingInfoAll(topic, id);
    }

    /**
     * 创建榜单
     * @param ranking
     */
    @Override
    public void createRanking(Ranking ranking) {
        rankingMapper.createRanking(ranking);
    }

    /**
     * 删除榜单
     * @param id
     */
    @Override
    public void deleteRanking(Integer id) {
        rankingMapper.deleteRanking(id);
    }

    /**
     * 更新榜单
     * @param ranking
     */
    @Override
    public void updateRanking(Ranking ranking) {
        rankingMapper.updateRanking(ranking);
    }

    /**
     * 获取评论分页信息
     * @param page
     * @param pageSize
     * @return
     */
    @Override
    public PageResult<CommentPageVo> getCommentsPage(Integer page, Integer pageSize) {
        PageHelper.startPage(page, pageSize);

        List<CommentPageVo> commentList = rankingMapper.getCommentsAll();

        Page<CommentPageVo> p = (Page<CommentPageVo>) commentList;

        return new PageResult<>(p.getTotal(), p.getResult());

    }

    /**
     * 修改评论状态
     * @param commentId
     * @param status
     */

    @Override
    public void updateCommentsStatus(Integer commentId, Integer status) {
        rankingMapper.updateCommentsStatus(commentId, status);
    }

    /**
     * 删除评论
     * @param commentId
     */
    @Override
    public void deleteComments(Integer commentId) {
        rankingMapper.deleteComments(commentId);
    }
}
